﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace FR.CodeVisualizer.Views
{
    public class ExecuteSQL
    {
        public static DataSet DevolveDataSetPorSql(string sql, string connetionString)
        {
            DataSet x = new DataSet();
            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection(connetionString);
                conn.Open();
                SqlDataAdapter sad = new SqlDataAdapter(sql, conn);
                sad.Fill(x);

                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                    conn.Dispose();
                }

                sad.Dispose();
                conn.Dispose();

                return x;
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }

            return null;
        }
    }
}
